package com.gupao.rpc.protocol.spring.reference;

import org.springframework.beans.factory.FactoryBean;

import java.lang.reflect.Proxy;

/**
 * 工厂bean
 */
public class SpringRpcReferenceFactoryBean implements FactoryBean<Object> {
    private Object object;
    private Class<?> classInterfaces;
    private String host;
    private int port;


    @Override
    public Object getObject() throws Exception {
        return this.object;
    }

    public void init() {
        this.object = Proxy.newProxyInstance(classInterfaces.getClassLoader(),
                new Class[]{classInterfaces}, new RpcInovkerProxy(host, port));
    }

    @Override
    public Class<?> getObjectType() {
        return classInterfaces;
    }

    public void setClassInterfaces(Class<?> classInterfaces) {
        this.classInterfaces = classInterfaces;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public void setPort(int port) {
        this.port = port;
    }
}
